import React, { useState, useEffect, useLayoutEffect } from "react";

export default function EffectCounterDemo02() {
  const [count, setCount] = useState(10);

  useLayoutEffect(() => {
    if (count === 0) {
      setCount(Math.random());
      // 这个地方渲染的数字,直接渲染随机数,没有一个闪的效果
    }
  }, [count]);
  return (
    <div>
      <h2>数字: {count}</h2>
      <button onClick={(e) => setCount(0)}>修改数字</button>
    </div>
  );
}
